package main

import (
	"fmt"
	"bufio"
	"os"
	"code.google.com/p/my-little-rpg/goMyLittleRPG/db"
	//"code.google.com/p/my-little-rpg/goMyLittleRPG/user"
)

const DB string = "database.db"

func welcomeMessage() {
	fmt.Println("|------------------------------|")
	fmt.Println("|++  Welcome to MyLittleRPG  ++|")
	fmt.Println("|------------------------------|")
}

func login() {
	r := bufio.NewReader(os.Stdin)
	for {
		fmt.Println("Do you have an account?")
		//msg, err := r.ReadString(delim)
		msg, err := r.ReadBytes('\n')
		//r.UnreadByte()
		if err != nil {
			fmt.Println(err.Error())
			os.Exit(1)
		}
		switch msg[0]  {
		case 'y':
			fmt.Println("affermative")
		case 'n':
			fmt.Println("negative")
		case 'q':
			fmt.Println("bye!")
			os.Exit(0)
		default:
			fmt.Println("huh?")
		}
	}
}

func init() {
	if exists, _ := db.Exists("./" + DB); !exists {
		fmt.Println("Creating database...")
		db.CreateDB(DB)
	}

}

func main() {
	welcomeMessage()
	login()
	/*
	u := user.New("bleh")
	err := db.InsertUser(u, DB)
	if err != nil {
		fmt.Println(err)
	}
	db.SelectAllUsers(DB)
	db.SelectUser(4, DB)
	*/


	/*
	Server* s = new Server("Petit");
	World* w = s->getWorld();
	s->printWelcomeMessage();
	string username;
	string cname;
	User* dm = s->createUser("dm");
	//while(1) {
	cout << "Enter your desired username: " << endl;
	cin >> username;
	User* u1 = s->createUser(username);
	cout << "Hello, " << u1->getUsername() << "!\n";
	cout << "Enter the name of your character: " << endl;
	cin >> cname;
	Character* c = u1->createRandomizedCharacter(cname);
	c->printCharacterSheet();
	Character* m = dm->createRandomizedCharacter("Random Goo Monster");
	cout << c->getName() << " you encountered a " << m->getName() << endl;
	m->printCharacterSheet();
	*/

	//}

	/*//u1->whoAmI();
	u1->setUsername("mikey");
	//u1->whoAmI();
	//u1.setUsername("mikey");
	//u1.whoAmI();
	//User u2("montana", 32);
	//u2.setUsername("tony");
	//u2.whoAmI();
	User* u2 = s->createUser("Tom", 37);
	u2->setUsername("tommy");
	User* u3 = s->Server::createUser("Ann", 23);
	u3->setUsername("annie");
	s->printUsers();
	//User user("Toby", 42);
	//user.whoAmI();
	//Die d20(20);
	//int roll = d20.roll();
	//cout << "The die rolled: " << roll << endl;
	//Character c("squiggs");
	Character* c = u1->createRandomizedCharacter("squiggs1");
	c->printCharacterSheet();
	u1->createRandomizedCharacter("squiggs2");
	u1->createRandomizedCharacter("squiggs3");
	u1->createRandomizedCharacter("squiggs4");
	u1->createRandomizedCharacter("squiggs5");
	u1->createRandomizedCharacter("squiggs6");
	u1->createRandomizedCharacter("squiggs7");
	u1->createRandomizedCharacter("squiggs8");
	u1->createRandomizedCharacter("squiggs9");
	u1->createRandomizedCharacter("squiggs10");
	try {
		u1->createRandomizedCharacter("squiggs11");
	} catch (TooManyCharactersException tmce) {
		cout << "Warning: " << tmce.what();
	}
	u1->printCharacters();*/



	//return 0;
}

